<template>
  <div>
    <el-container :gutter="24">
      <el-aside style="margin-top:0;width: 250px;background-color: #a7cced">
        <el-col>
          <h5 style="text-align: center;">医生端</h5>
          <el-menu
              active-text-color="#FF0000FF"
              background-color="#8faecd"
              class="el-menu-vertical-demo"
              text-color="#000"
          >
            <el-menu-item index="1" @click="goRegister">
              <el-icon>
                <Pointer/>
              </el-icon>
              <span>
                  叫号
              </span>
            </el-menu-item>
            <el-menu-item index="2" @click="goMedical">
              <el-icon>
                <Tickets/>
              </el-icon>
              <span>
                  药品管理
              </span>
            </el-menu-item>
            <el-menu-item index="3" @click="goInv">
              <el-icon>
                <Files />
              </el-icon>
              <span>
                  库存管理
              </span>
            </el-menu-item>
          </el-menu>
        </el-col>
      </el-aside>
      <el-main style="padding: 0;" :span="19">
        <el-container>
          <el-header style="background-color: #a7cced;">
            <div class="header-content">
              欢迎您！ {{ username }}
              <el-dropdown trigger="click" @command="handleCommand" style="margin-left: 10px">
                  <span class="el-dropdown-link">
                     <el-icon class="el-icon--right">
                       <arrow-down/>
                     </el-icon>
                  </span>
                <template #dropdown>
                  <el-dropdown-menu>
                    <el-dropdown-item command="a">叫号</el-dropdown-item>
                    <el-dropdown-item command="c" divided>退出</el-dropdown-item>
                  </el-dropdown-menu>
                </template>
              </el-dropdown>
            </div>
          </el-header>
          <el-main style="height: 100%">
            <router-view/>
          </el-main>
        </el-container>
      </el-main>
    </el-container>
  </div>
</template>

<script>
import jsCookie from "jscookie";
import {ElMessage, ElMessageBox} from "element-plus";
import {ArrowDown, Files, Money, Pointer, Tickets, User} from "@element-plus/icons-vue";
import {fetchUser} from "@/api/doc.js";

export default {
  name: "doctorHome",
  components: {Files, ArrowDown, Money, User, Tickets, Pointer},
  data() {
    return {
      username: '',
      token: '',
      messageCount: 0
    }
  },
  created() {
    this.token = jsCookie.get('token');
    this.fetchUsername();
  },
  methods: {
    async fetchUsername() {
      const response = await fetchUser(this.token);
      this.username = response.data.data.docName;
    },
    goRegister() {
      this.$router.push('/doctorHome/callNum');
    },
    goMedical() {
      this.$router.push('/doctorHome/drug');
    },
    goInv() {
      this.$router.push('/doctorHome/inv');
    },
    handleCommand(command) {
      if (command == 'a') {
        this.$router.push('/doctorHome/callNum');
      } else if (command == 'c') {
        ElMessageBox.confirm(this.username + '您确定要退出登录吗？', '友情提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          jsCookie.del('username');
          jsCookie.del('token');
          this.$router.push('/login');
          ElMessage({
            message: '退出登录成功!',
            type: 'success',
          });
        });
      }
    },
  }
}
</script>

<style scoped>
.example-showcase .el-dropdown-link {
  cursor: pointer;
  color: var(--el-color-primary);
  display: flex;
  align-items: center;
}

.header-content {
  display: flex;
  justify-content: flex-end; /* 将内容右对齐 */
  align-items: center; /* 垂直居中对齐 */
  height: 100%; /* 确保高度占满整个header */
}
</style>
